package demo2

type Cloneable interface {
	Clone() Cloneable
}

type PrototypeManager struct {
	prototypes map[string]Cloneable
}

func NewPrototypeManager() *PrototypeManager {
	return &PrototypeManager{
		prototypes: make(map[string]Cloneable),
	}
}

func (p *PrototypeManager) Get(name string) Cloneable {
	return p.prototypes[name]
}

func (p *PrototypeManager) Set(name string, prototype Cloneable) {
	p.prototypes[name] = prototype
}

// ------------------------------------------------------------
// 原型设计模式 有点类似 redo undo 和注册发现，链式操作

type Cloneable_1 interface {
	Clone() Cloneable_1
}

type PrototypeManager_1 struct {
	prototypes map[string]Cloneable_1
}

func NewPrototypeManager_1() *PrototypeManager_1 {
	return &PrototypeManager_1{
		prototypes: make(map[string]Cloneable_1),
	}
}

func (p *PrototypeManager_1) Get(name string) Cloneable_1 {
	return p.prototypes[name]
}

func (p *PrototypeManager_1) Set(name string, cloneable Cloneable_1) {
	p.prototypes[name] = cloneable
}
